package logic

import (
	"context"
	"store/model/mysql"
	"store/userrpc/userrpcclient"

	"store/userrpc/internal/svc"
	"store/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *userrpc.ListRequest) (*userrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var store []mysql.Store
	mysql.DB.Debug().Find(&store)

	var lists []*userrpcclient.StoreList
	for _, m := range store {
		list := userrpcclient.StoreList{
			Id:   int64(m.ID),
			Name: m.Name,
			Addr: m.Addr,
			Tel:  m.Tel,
		}
		lists = append(lists, &list)

	}

	return &userrpc.ListResponse{List: lists}, nil
}
